﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    [ObjectEvent]
    public class RM_001Event : ObjectEvent<RM_001>, IAwake
    {
        public void Awake()
        {
            Get().Awake();
        }
    }

    //本卡命中时，你可从卡组展示一张“梦想封印”并加入手牌，然后你回复1点灵力。
    public class RM_001 : BattleEventComponent
    {
        public override BattleEventType[] EventType { get; set; } = new BattleEventType[] { BattleEventType.AttackSuccess };

        public override async Task RunEvent(BattleEventType eventType, FightModel fightModel, params object[] param)
        {
            DamageInfo damageInfo = param[0] as DamageInfo;
            if (damageInfo.AttackCard == GetEntity<BattleCard>())
            {
                List<BattleCard> ShowCard = new List<BattleCard>();
                foreach(var card in fightModel.nowPlayer[CardPlace.Deck].Cards)
                {
                    if (card.SearchType == CardSearchType.梦想封印)
                        ShowCard.Add(card);
                }
                SearchInfo searchInfo = new SearchInfo()
                {
                    MaxChooseNum=1,
                    Condition = (x) =>
                    {
                        if (x.Count == 0) return false;
                        return x[0].SearchType==CardSearchType.梦想封印;
                    },
                    ShowCard= ShowCard,
                    OnSure = async (x) =>
                    {
                        x[0].IfRightSide = true;
                        fightModel.nowPlayer[CardPlace.Deck].MoveCards(fightModel.nowPlayer[CardPlace.Hand], x);
                        fightModel.nowPlayer.RecoverPower(1);
                        await BattleEventWatcherComponent.Single.RunEvent(BattleEventType.FreshUI, fightModel);
                    },
                    OnCancel = async (x) =>
                    {
                        fightModel.nowPlayer.RecoverPower(1);//恢复灵力必定执行
                        await BattleEventWatcherComponent.Single.RunEvent(BattleEventType.FreshUI, fightModel);
                    },
                };
                await BattleEventWatcherComponent.Single.RunEvent(BattleEventType.ShowWindow, fightModel,WindowType.Search, searchInfo);
            }
        }
    }
}
